package zd.vrp.utils;

import java.util.List;

import zd.vrp.global.City;
import zd.vrp.global.GlobalInformation;
import zd.vrp.global.Route;

public class TestUtils {
	public static double getTotalLength(List<Route> routeList){
		double d = 0;
		for(Route route:routeList){
			for(int j=0;j<route.getCityList().size()-1;j++){
				City thisCity = route.getCityList().get(j);
				City nextCity = route.getCityList().get(j+1);
				d += GlobalInformation.distance[thisCity.getId()*GlobalInformation.cityNum+nextCity.getId()];
			}
		}
		return d;
	}
	

	public static void showSolution(List<Route> routeList) {
		System.out.println("routelist size:"+routeList.size());
		for (int i = 0; i < routeList.size(); i++) {
			Route r = routeList.get(i);
			System.out.print("route " + r + ": ");
			for (int j = 0; j < r.getCityList().size(); j++) {
				City c = r.getCityList().get(j);
				System.out.print(c.getId() + "-");
			}
			System.out.println("---------");
		}	
		System.out
		.println("total length:" + getTotalLength(routeList));
	}

	public static void showSolution() {

		for (int i = 0; i < GlobalInformation.routeList.size(); i++) {
			Route r = GlobalInformation.routeList.get(i);
			System.out.print("route " + r + ": ");
			for (int j = 0; j < r.getCityList().size(); j++) {
				City c = r.getCityList().get(j);
				System.out.print(c.getId() + "-");
			}
			System.out.println("---------");
		}

		System.out
				.println("total length:" + GlobalInformation.getRouteLength());
		System.out.println("total duration:"
				+ GlobalInformation.getRouteDuration());
		System.out.println("time feasibility:"
				+ GlobalInformation.checkTimeFeasibility());
		System.out.println("demand feasibility:"
				+ GlobalInformation.checkDemandFeasibility());
	}

	public static void showSolutionDetails() {
		for (int i = 0; i < GlobalInformation.routeList.size(); i++) {
			Route r = GlobalInformation.routeList.get(i);
			System.out.print("route " + r + ": ");
			for (int j = 0; j < r.getCityList().size(); j++) {
				City c = r.getCityList().get(j);
				System.out.print(c.getId() + "(" + c.getArrivalTime() + ":"
						+ c.getStartTime() + ":" + c.getFinishTime() + ":"
						+ c.getEtime() + ":" + c.getLtime() + ")-");
			}
			System.out.println("---------");
		}

		System.out
				.println("total length:" + GlobalInformation.getRouteLength());
		System.out.println("total duration:"
				+ GlobalInformation.getRouteDuration());
	}

	public static void showMessage(Object o) {
		// System.out.println(o);
	}
	
	public static void showRoute(Route r){
		for (int j = 0; j < r.getCityList().size(); j++) {
			City c = r.getCityList().get(j);
			System.out.print(c.getId() + "-");
		}
		System.out.println("---------");
	}
}
